//
//  HeadersMiddleware.swift
//  App
//
//  Created by melvyn on 2018/9/19.
//

import Foundation
import Vapor

class HeadersMiddleware: Middleware, ServiceType {
    
    static func makeService(for worker: Container) throws -> Self {
        return .init()
    }
    
    public required init () {}
    
    func respond(to request: Request, chainingTo next: Responder) throws -> EventLoopFuture<Response> {
        
        return try next.respond(to: request)
            .map({ (response) -> (Response) in
                response.http.headers.replaceOrAdd(name: "Cache-Control", value: "max-age=5")
                return response
            })
    }
}
